package org.linloong.core.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author lz
 * @date 2022/5/23 14:21
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result<T> {

    private Integer code;
    private String message;
    private T data;
    private boolean result;

    public static <T> Result<T> success() {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null,true);
    }

    public static <T> Result<T> success(T t) {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), t,true);
    }

    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(code, message, null,false);
    }

    public static <T> Result<T> fail() {
        return new Result<>(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), null,false);
    }
    public static <T> Result<T> fail(String message) {
        return new Result<>(ResultEnum.FAIL.getCode(), message, null,false);
    }
}
